﻿@using CubicFWNet.Data.Models
@using CubicFWNet.Data.ViewModal
@model Worksheet
@{
    //ViewBag.Title = "生产加工单";
    var technology = ViewBag.Technology as Technology;
    //var orderProduct = ViewBag.OrderProduct as OrderProduct;
    var product = ViewBag.Product as Product;
    var order = ViewBag.Order as Order;
    var techType = ViewBag.TechType as TechType;
    var productTechnologyView = ViewBag.ProductTechnologyView as ProductTechnologyView;
    //var technologyItemList = ViewBag.TechnologyItemList as List<ProductTechnologyView>;
    var listEquipments = ViewBag.ListEquipments as IEnumerable<Equipment>;
    var operationName = ViewBag.OperationName;
    var operationTime = ViewBag.OperationTime;
    var wrksheetNumber = ViewBag.WorksheetNumber;
    var levelList = ViewBag.LevelList as List<TechType>;
}
<section class="content-header">
    <h1>
        生产加工单
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index", "Home")">首页</a></li>
        <li class="active"><a href="@Url.Action("Check", "Worksheet")">加工单</a></li>
    </ol>
</section>
<section class="content">
    <div class="box box-solid">
        <!-- /.box-header -->
        <div class="box-body">
            <div class="row">
                @if (Model != null && product != null && technology != null && productTechnologyView != null && techType != null && order != null)
                {
                    <form class="form-horizontal" id="frmedit" action="@Url.Action("AddCheck", "Worksheet")" method="post">
                        <input type="hidden" id="Id" name="Id" value="@Model.Id" />
                        <input type="hidden" id="TechnologyId" name="TechnologyId" value="@technology.Id" />
                        <input type="hidden" id="ApplyTime" name="ApplyTime" value="@Model.ApplyTime" />
                        <input type="hidden" id="eType" value="@technology.EquipmentType" />
                        <input type="hidden" id="tType" value="@technology.TechType" />
                        <input type="hidden" id="Ch" value="@technology.Ch" />@*//刀模数[左右]*@
                        <input type="hidden" id="Cv" value="@technology.Cv" />@*//刀模数[排]*@
                        <input type="hidden" id="Space" value="@technology.Space" />@*//左右间距-mm*@
                        <input type="hidden" id="Margin" value="@product.Margin">@*左右边距-mm*@
                        <input type="hidden" id="Distance" value="@product.Distance">@*跳距-mm*@

                        <input type="hidden" id="SizeWidth" value="@product.SizeWidth">@*尺寸宽-mm*@
                        <input type="hidden" id="SizeLenth" value="@product.SizeLenth">@*尺寸长-mm*@
                        <input type="hidden" id="MinuteNum" value="@techType.MinuteNum" />
                        <input type="hidden" id="ProductId" value="@Model.ProductId" />
                        <input type="hidden" id="Type" value="@Model.Type" />@*0:正常生产  1：补单生产*@
                        <input type="hidden" id="OtherId" name="OtherId" value="@order.Id" />

                        <div class="box-body">
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">加工单编号</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="Number" name="Number" value="@wrksheetNumber" readonly="readonly" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">订单编号</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="orderNumber" name="orderNumber" value="@order.Number" readonly="readonly" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">产品名称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="ProductName" name="ProductName" value="@product.Name" readonly="readonly" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">订货数量</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="ProductAccount" name="ProductAccount" value="@Model.WorkAmount" readonly="readonly" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">合格数量</label>
                                <div class="col-sm-9">
                                    @if (Model.Type == 1)
                                    {
                                        <input type="text" class="form-control" id="StandardAmount" name="StandardAmount" value="0" readonly="readonly" />
                                    }
                                    else
                                    {
                                        <input type="text" class="form-control" id="StandardAmount" name="StandardAmount" value="@Model.StandardAmount" readonly="readonly" />
                                    }
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">本次生产数量</label>
                                <div class="col-sm-9">
                                    <input type="hidden" id="hidWorkAmount" value="@Model.WorkAmount"/>
                                    @if (Model.Status != -1)
                                    {
                                        <input type="text" class="form-control okeydown" id="WorkAmount" name="WorkAmount" value="@Model.WorkAmount" readonly="readonly" />
                                    }
                                    else
                                    {
                                        <input type="text" class="form-control okeydown" id="WorkAmount" name="WorkAmount" value="@Model.WorkAmount" required />
                                    }
                                </div>
                            </div>
                            <div class="form-group col-md-6" style="display: none">
                                <label class="col-sm-3 control-label">版本</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="Edition" name="Edition" value="000" />
                                </div>
                            </div>

                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">长-mm</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="SizeLenthback" name="SizeLenthback" value="@product.SizeLenth" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">宽-mm</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="SizeWidthback" name="SizeWidthback" value="@product.SizeWidth" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">刀模数[左右]</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="Chback" name="Chback" value="@technology.Ch" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">刀模数[排]</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="Cvback" name="Cvback" value="@technology.Cv" />
                                </div>
                            </div>

                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div id="json-material">
                                <div class="form-group col-md-6">
                                    <label for="ProductName" class="col-sm-3 control-label">主原材料</label>
                                    <div class="col-sm-9" style="padding-top: 7px; margin-bottom: 0;">
                                        <a href="javascript:void(0)" class="productinfo" data-tid="@productTechnologyView.Id" data-mid="@productTechnologyView.ProductId">@productTechnologyView.ProductName</a>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label for="ProductName" class="col-sm-3 control-label">工艺详情</label>
                                    <div class="col-sm-9" style="padding-top: 7px; margin-bottom: 0;">
                                        <a href="javascript:void(0)" class="technologyinfo" data-tid="@productTechnologyView.Id" data-mid="@productTechnologyView.ProductId">【@productTechnologyView.ProductName】 工艺详情</a>
                                    </div>
                                </div>
                                @*@if (technologyItemList != null)
                                    {
                                        foreach (var item in technologyItemList)
                                        {
                                            <div class="listProItem-content">
                                                <div class="form-group col-md-6">
                                                    <label for="ProductName" class="col-sm-3 control-label">辅料名称</label>
                                                    <div class="col-sm-9" style="padding-top: 7px; margin-bottom: 0;">
                                                        <span>@item.ProductName</span>
                                                    </div>
                                                </div>
                                                <div class="form-group col-md-6">
                                                    <label for="ProductName" class="col-sm-3 control-label">工艺详情</label>
                                                    <div class="col-sm-9" style="padding-top: 7px; margin-bottom: 0;">
                                                        <a href="javascript:void(0)" class="technologyinfo" data-tid="@item.Id" data-mid="@item.ProductId">【@item.ProductName】 工艺详情</a>
                                                    </div>
                                                </div>
                                            </div>
                                        }
                                    }*@
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">设备</label>
                                <div class="col-sm-9">
                                    <select class="form-control" type="select" data-des="设备" id="EquipmentType" name="EquipmentType">
                                        <option value="0">==请选择==</option>
                                        @if (listEquipments != null)
                                        {
                                            foreach (var item in listEquipments)
                                            {
                                                <option value="@item.Id">@item.EquipmentName</option>
                                            }
                                        }
                                    </select>
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">类别</label>
                                <div class="col-sm-9">
                                    <select class="form-control" type="select" data-des="类别" id="TechType" name="TechType">
                                        @if (levelList != null)
                                        {
                                            foreach (var item in levelList)
                                            {
                                                <option value="@item.TechTypeId">@item.TechTypeName</option>
                                            }
                                        }
                                        else
                                        {
                                            <option value="0" selected="selected">==请选择==</option>
                                        }
                                    </select>
                                </div>
                            </div>

                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div id="work-content">
                                <div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">分条时间-分钟</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control okeydown" data-des="分条时间-分钟" id="j_a" name="j_a" value="">
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label okeydown">单张厚度</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" data-des="单张厚度" id="j_b" name="j_b" value="">
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label okeydown">整包厚度</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" data-des="整包厚度" id="j_c" name="j_c" value="">
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">其他维修时间记录</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" data-des="其他维修时间记录" id="j_d" name="j_d" value="">
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">包装要求</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" data-des="包装要求" id="j_f" name="j_f" value="">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">预计加工工时-分钟</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control okeydown" id="ExpectedHours" name="ExpectedHours" value="@technology.WorkLenth" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">实际加工工时-分钟</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control okeydown" id="ActualHours" name="ActualHours" value="">
                                </div>
                            </div>

                            <div class="form-group col-md-6" style="display: none">
                                <label class="col-sm-3 control-label">领料</label>
                                <div class="col-sm-9">
                                    <span class="btn btn-primary" id="showLing" style="margin-top: 5px;">添加行数</span>
                                </div>
                            </div>
                            @*<div class="form-group col-md-12" style="height: 1px;"></div>*@
                            <div id="ling-content" style="display: none">
                                <div class="lingItem-content">
                                    <div class="form-group col-md-4">
                                        <label class="col-sm-3 control-label">长-m</label>
                                        <div class="col-sm-9">
                                            <input type="hidden" id="l_name" name="l_name" value="@product.Name">
                                            <input type="text" class="form-control okeydown" data-des='长-m' id="l_length" name="l_length" value="">
                                        </div>
                                    </div>
                                    <div class="form-group col-md-4">
                                        <label class="col-sm-3 control-label">宽-mm</label>
                                        <div class="col-sm-9">
                                            <input type="text" class="form-control okeydown" data-des='宽-mm' id="l_width" name="l_width" value="">
                                        </div>
                                    </div>
                                    <div class="form-group col-md-4">
                                        <label class="col-sm-3 control-label">数量</label>
                                        <div class="col-sm-9">
                                            <input type="text" class="form-control okeydown" data-des='数量' id="l_amount" name="l_amount" value="">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            @*<div class="form-group col-md-12" style="height: 1px;"></div>*@
                            <div class="form-group col-md-6" style="display: none">
                                <label class="col-sm-3 control-label" style="display: none">退料</label>
                                <div class="col-sm-9">
                                    <span class="btn btn-primary" id="showTui" style="margin-top: 5px;">添加行数</span>
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div id="tui-content" style="display: none">
                                <div class="tuiItem-content">
                                    <div class="form-group col-md-4">
                                        <label class="col-sm-3 control-label">长-m</label>
                                        <div class="col-sm-9">
                                            <input type="hidden" id="l_name" name="l_name" value="@product.Name">
                                            <input type="text" class="form-control okeydown" data-des='长-m' id="l_length" name="l_length" value="">
                                        </div>
                                    </div>
                                    <div class="form-group col-md-4">
                                        <label class="col-sm-3 control-label">宽-mm</label>
                                        <div class="col-sm-9">
                                            <input type="text" class="form-control okeydown" data-des='宽-mm' id="l_width" name="l_width" value="">
                                        </div>
                                    </div>
                                    <div class="form-group col-md-4">
                                        <label class="col-sm-3 control-label">数量</label>
                                        <div class="col-sm-9">
                                            <input type="text" class="form-control okeydown" data-des='数量' id="l_amount" name="l_amount" value="">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">预计用料</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control okeydown" id="ExpectedMaterial" name="ExpectedMaterial" value="" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">实际用料</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control okeydown" id="ActualMaterial" name="ActualMaterial" value="">
                                </div>
                            </div>

                            @*<div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">总重量</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control okeydown" id="TotalWeight" name="TotalWeight" value="" required>
                                    </div>
                                </div>*@
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">备注</label>
                                <div class="col-sm-9">
                                    <textarea class="form-control" rows="3" placeholder="请输入 ..." name="Memo" id="Memo"></textarea>
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">注意事项与工艺</label>
                                <div class="col-sm-9">
                                    <textarea class="form-control" rows="3" placeholder="请输入 ..." name="TechnologMemo" id="TechnologMemo">@Model.TechnologMemo</textarea>
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label for="operationName" class="col-sm-3 control-label">操作人</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationName" name="operationName" value="@operationName" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="operationTime" class="col-sm-3 control-label">日期</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationTime" name="operationTime" value="@operationTime" readonly="readonly">
                                </div>
                            </div>
                        </div>
                        <div class="box-footer" style="width: 80%; margin-left: 20px;">
                            @if (Model.Status != -1)
                            {
                                <a role="button" href="javascript:void(0)" class="btn btn-primary submitbtn" onclick="formsubmit(1)">确认</a>
                            }
                            else
                            {
                                <a class="btn btn-primary" onclick="PrintWorksheet()" href="javascript:void(0)">打印</a>
                            }
                            <a role="button" href="@Url.Action("Check", "Worksheet")" class="btn btn-primary">返回</a>
                            <div class="text-red" style="margin-top:20px;font-weight:bold">下一步：检验管理-->检验查询</div>
                        </div>
                    </form>
                }
            </div>
        </div>
    </div>
</section>

<div id="loadingPage" style="display: none;">
    <div class="loading-shade"></div>
    <div class="loading-content" onclick="$.loading(false)">数据加载中，请稍后…</div>
</div>

@section Scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            $("#frmedit").validate({
                submitHandler: function (form) {
                    var postData = $(form).formSerialize();
                    postData.Data = getParam();//JSON.stringify(postData._Data);
                    postData.LingData = getParamLing();
                    postData.TuiData = getParamTui();
                    $.submitForm({
                        url: $(form).attr("action"),
                        param: postData,
                        success: function () {
                            //$.reload();
                            $.modalAlert("操作成功", "success");
                            window.location.href = '@Url.Action("Query", "Worksheet")';
                        }
                    });
                }
            });

            var etype = $("#eType").val();
            var ttype = $("#tType").val();
            $("#EquipmentType").val(etype);
            $("#TechType").val(ttype);

            var amount = $("#WorkAmount").val() / 1;//生产数量
            calculate(amount);
        });

        function formsubmit(t) {
            var wtype = $("#Type").val();
            if (wtype == "1") {
                var hidWorkAmountAgain = $("#hidWorkAmountAgain").val() / 1;//还需最大生产量
                var workAmountAgain = $("#WorkAmountAgain").val();//本次生产量
                if (workAmountAgain == "" || (workAmountAgain / 1 > hidWorkAmountAgain)) {
                    $.modalAlert("生成总数大于订购数", "warning");
                    return false;
                }
            }

            var etype = $("#EquipmentType").val();
            var ttype = $("#TechType").val();
            if (etype == "0") {
                $.modalAlert("请选择设备", "warning");
                return false;
            }
            if (ttype == "0") {
                $.modalAlert("请选择类别", "warning");
                return false;
            }
            getParamLing();
            getParamTui();
            $("#frmedit").submit();
        }

        //设备
        $("#EquipmentType").change(function () {
            var equipmentType = $(this).val();
            if (equipmentType == "0") {
                return;
            }
            var techType = $("#TechType").val();
            changeType(equipmentType, techType);
        });
        //类别
        $("#TechType").change(function () {
            var techType = $(this).val();
            if (techType == "0") {
                return;
            }
            var equipmentType = $("#EquipmentType").val();
            changeType(equipmentType, techType);
        });

        //打印
        function PrintWorksheet() {
            var id = $("#Id").val();
            var sl = $("#SizeLenthback").val();
            var sw = $("#SizeWidthback").val();
            var ch = $("#Chback").val();
            var cv = $("#Cvback").val();
            var tMemo = $("#TechnologMemo").val();
            var amount = $("#WorkAmount").val();
            var productAccount = $("#ProductAccount").val();
            var equipmentName = $("#EquipmentType").find("option:selected").text();
            //console.log(tMemo);
            window.location.href = "/Worksheet/PrintWorksheet?tId=" + id + "&sl=" + sl + "&sw=" + sw + "&ch=" + ch + "&cv=" + cv + "&tMemo=" + tMemo + "&count=" + amount + "&pac=" + productAccount + "&eqName=" + equipmentName;
        }

        function changeType(equipmentType, techType) {
            $.ajax({
                url: '@Url.Action("WorksheetChangeType", "Worksheet")',
                type: "post",
                data: {
                    equipmentType: equipmentType,
                    techType: techType
                },
                success: function (data) {
                    var minuteNum = JSON.parse(data);
                    var amount = $("#WorkAmount").val() / 1;//生产数量
                    var ch = $("#Ch").val() / 1;//刀模数[左右]
                    var cv = $("#Cv").val() / 1;//刀模数[排]
                    var gg = Math.ceil(amount / (ch * cv));

                    if ((minuteNum / 1) == 0) {
                        $("#ExpectedHours").val(0);
                    } else {
                        var workLenth = gg / (minuteNum / 1);
                        if (workLenth.toFixed(2) < 1) {
                            workLenth = 1;
                        }
                        $("#ExpectedHours").val(workLenth);
                    }

                },
                error: function (xhr, err, state) {
                    console.log("e");
                }
            });
        }


        function getParam() {
            var postdata = [];
            //主键
            $("#work-content").find('input,select,textarea').each(function (r) {
                var $this = $(this);
                var id = $this.attr('id');
                var type = $this.attr('type');
                if (id) {
                    switch (type) {
                        case "checkbox":
                            postdata.push({ des: $this.attr("data-des"), name: id, value: $this.is(":checked") });
                            break;
                        case "select":
                            var value = $this.find("option:selected").val() == "" ? null : $this.find("option:selected").val();
                            postdata.push({ des: $this.attr("data-des"), name: id, value: value });
                            break;
                        default:
                            var value = $this.val() == "" ? "&nbsp;" : $this.val();
                            postdata.push({ des: $this.attr("data-des"), name: id, value: value });
                            break;
                    }
                }
            });
            return JSON.stringify(postdata);
        }

        //领料json
        function getParamLing() {
            var postdata = [];
            $("#ling-content").find('.lingItem-content').each(function (r, i) {
                var technologyItem = {};
                $(i).find('input').each(function (m) {
                    var $this = $(this);
                    var id = $this.attr('id');
                    var value = $this.val() == "" ? "0" : $this.val();
                    if (id) {
                        technologyItem[id] = value;
                    }
                });
                postdata.push(technologyItem);
            });
            console.log(postdata);
            return JSON.stringify(postdata);
        }
        //领料json
        function getParamTui() {
            var postdata = [];
            $("#tui-content").find('.tuiItem-content').each(function (r, i) {
                var technologyItem = {};
                $(i).find('input').each(function (m) {
                    var $this = $(this);
                    var id = $this.attr('id');
                    var value = $this.val() == "" ? "0" : $this.val();
                    if (id) {
                        technologyItem[id] = value;
                    }
                });
                postdata.push(technologyItem);
            });
            console.log(postdata);
            return JSON.stringify(postdata);
        }


        //领料添加行数
        $("#showLing").click(function () {
            var proName = $("#ProductName").val();
            var phtml = [];
            phtml.push("<div class='lingItem-content'>");
            phtml.push("<div class='form-group col-md-4'><label class='col-sm-3 control-label'>长-m</label>");
            phtml.push("<div class='col-sm-9'><input type='hidden' id='l_name' name='l_name' value='" + proName + "'><input type='text' class='form-control okeydown' data-des='长-m' id='l_length' name='l_length' value=''></div></div>");
            phtml.push("<div class='form-group col-md-4'><label class='col-sm-3 control-label'>宽-mm</label>");
            phtml.push("<div class='col-sm-9'><input type='text' class='form-control okeydown' data-des='宽-mm' id='l_width' name='l_width' value=''></div></div>");
            phtml.push("<div class='form-group col-md-4'><label class='col-sm-3 control-label'>数量</label>");
            phtml.push("<div class='col-sm-9'><input type='text' class='form-control okeydown' data-des='数量' id='l_amount' name='l_amount' value=''></div></div>");
            phtml.push("</div>");
            $("#ling-content").append(phtml.join(""));

        });

        //退料添加行数
        $("#showTui").click(function () {
            var proName = $("#ProductName").val();
            var phtml = [];
            phtml.push("<div class='tuiItem-content'>");
            phtml.push("<div class='form-group col-md-4'><label class='col-sm-3 control-label'>长-m</label>");
            phtml.push("<div class='col-sm-9'><input type='hidden' id='l_name' name='l_name' value='" + proName + "'><input type='text' class='form-control okeydown' data-des='长-m' id='l_length' name='l_length' value=''></div></div>");
            phtml.push("<div class='form-group col-md-4'><label class='col-sm-3 control-label'>宽-mm</label>");
            phtml.push("<div class='col-sm-9'><input type='text' class='form-control okeydown' data-des='宽-mm' id='l_width' name='l_width' value=''></div></div>");
            phtml.push("<div class='form-group col-md-4'><label class='col-sm-3 control-label'>数量</label>");
            phtml.push("<div class='col-sm-9'><input type='text' class='form-control okeydown' data-des='数量' id='l_amount' name='l_amount' value=''></div></div>");
            phtml.push("</div>");
            $("#tui-content").append(phtml.join(""));

        });

        $("#WorkAmount").keyup(function () {
            var thisAmount = $(this).val();//生产数量
            var amount = $("#hidWorkAmount").val() / 1;
            if (isNaN(thisAmount)) {
                $("#WorkAmount").val(1);
                thisAmount = 1;
            }
            thisAmount = thisAmount / 1;
            if (thisAmount < 1) {
                $("#WorkAmount").val(1);
                thisAmount = 1;
            }
            if (thisAmount > amount) {
                $("#WorkAmount").val(amount);
                thisAmount = amount;
            }
            calculate(thisAmount);
        });

        function calculate(thisAmount) {
            var sizeWidth = $("#SizeWidth").val() / 1; //尺寸宽-mm
            var sizeLenth = $("#SizeLenth").val() / 1; //尺寸长-mm
            var ch = $("#Ch").val() / 1;//刀模数[左右]
            var cv = $("#Cv").val() / 1;//刀模数[排]
            var space = $("#Space").val() / 1; //左右间距-mm
            var margin = $("#Margin").val() / 1; //左右边距-mm
            var distance = $("#Distance").val() / 1; //跳距-mm

            var giveW = (sizeWidth * ch + (ch - 1) * space + margin * 2 + 15) / 1000;//给定用料宽-m(米)
            var comH = thisAmount / ch;
            var giveH = (sizeLenth + distance) * comH / 1000;//给定用料长-m(米)
            var area = giveW * giveH;
            $("#ExpectedMaterial").val(area.toFixed(2));

            var equipmentType = $("#EquipmentType").val();
            var techType = $("#TechType").val();
            changeType(equipmentType, techType);
        }

        function Workminute() {

        }

        $("#EquipmentType").change(function () {
            var selectVal = $(this).val();
            $.ajax({
                url: "../Technology/GetLevelList",
                type: "post",
                data: {
                    selectVal: selectVal
                },
                success: function (data) {
                    if (data && JSON.parse(data)) {
                        var list = JSON.parse(data);
                        console.log(list);
                        $("#TechType").html("");
                        var html = [];
                        if (list.length > 0) {
                            for (var i = 0; i < list.length; i++) {
                                html.push("<option value=" + list[i].TechTypeId + ">" + list[i].TechTypeName + "</option>");
                            }
                        } else {
                            html.push("<option value='0' selected='selected'>==请选择==</option>");
                        }
                        $("#TechType").html(html);
                    } else {
                        alert("暂无参数");
                    }
                },
                error: function (xhr, err, state) {
                    //alert("e");
                }
            });
        });

        $(".technologyinfo").click(function () {
            var tid = $(this).data('tid');
            var mid = $(this).data('mid');
            var options = {
                id: null,
                title: '产品信息',
                width: "100%",
                height: "100%",
                url: "../Technology/TechnologyInfo?tId=" + tid + "&mId=" + mid,
                shade: 0.3,
                btn: ['返回'],
                btnclass: ['btn btn-danger'],
                callBack: null
            }
            $.modalOpen(options);
        });

        $(".productinfo").click(function () {
            var mid = $(this).data('mid');
            var options = {
                id: null,
                title: '产品信息',
                width: "100%",
                height: "100%",
                url: "../Product/Info?PID=" + mid,
                shade: 0.3,
                btn: ['返回'],
                btnclass: ['btn btn-danger'],
                callBack: null
            }
            $.modalOpen(options);
        });

        $(".okeydown").on("keydown", function () {
            var k = event.keyCode;
            if ((k <= 57 && k >= 48) || (k <= 105 && k >= 96) || (k == 8) || (k == 110) || (k == 190)) {
                return true;
            } else {
                return false;
            }
        });

    </script>
}